using System;
using System.Data;

using SqlHelperForCry.Common;

namespace Torch.WL.Entity
{
    [Table("Tb_Person", "personId", "Torch.WL.ConnectionString")]
	public class Tb_Person : Info
	{
		#region SQL column name consts 
		public const string SQLCOL_PERSONID = "personId";
		public const string SQLCOL_PERSONNAME = "personName";
		public const string SQLCOL_WORKCOMPANY = "workCompany";
		public const string SQLCOL_ADDRESS = "address";
		public const string SQLCOL_PROVINCE = "province";
		public const string SQLCOL_CITY = "city";
		public const string SQLCOL_MOBILE = "mobile";
		public const string SQLCOL_EMAIL = "email";
		public const string SQLCOL_CREATETIME = "createTime";
		#endregion


		#region Contructors
		/// <summary>
		/// Construct empty entity
		/// </summary>
		public Tb_Person () {}

		/// <summary>
		/// Construct entity by primary key, other fields will be assigned by 
		/// "Load" method.
		/// </summary>
		public Tb_Person (int personId)
		{
			this.personId = personId;
		}
		#endregion

		public override void Init (DataRow row)
		{
			personId = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_PERSONID]);
			personName = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_PERSONNAME]);
			workCompany = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_WORKCOMPANY]);
			address = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_ADDRESS]);
			province = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_PROVINCE]);
			city = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_CITY]);
			mobile = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_MOBILE]);
			email = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_EMAIL]);
			createTime = (DateTime)ObjectType.DateTimeTypeHelper.Read(row[SQLCOL_CREATETIME]);
		}

		#region Properties 
		#region Property <int> personId
		[Property("personId", 4, SqlDbType.Int, true, true)]
		public int personId 
		{
			get { return _personId; }
			set { _personId = value; }
		}
		private int _personId = int.MinValue;
		#endregion

		#region Property <string> personName
		[Property("personName", 50, SqlDbType.VarChar, false, false)]
		public string personName 
		{
			get { return _personName; }
			set { _personName = value; }
		}
		private string _personName = null;
		#endregion

		#region Property <string> workCompany
		[Property("workCompany", 200, SqlDbType.VarChar, false, false)]
		public string workCompany 
		{
			get { return _workCompany; }
			set { _workCompany = value; }
		}
		private string _workCompany = null;
		#endregion

		#region Property <string> address
		[Property("address", 300, SqlDbType.VarChar, false, false)]
		public string address 
		{
			get { return _address; }
			set { _address = value; }
		}
		private string _address = null;
		#endregion

		#region Property <string> province
		[Property("province", 50, SqlDbType.VarChar, false, false)]
		public string province 
		{
			get { return _province; }
			set { _province = value; }
		}
		private string _province = null;
		#endregion

		#region Property <string> city
		[Property("city", 50, SqlDbType.VarChar, false, false)]
		public string city 
		{
			get { return _city; }
			set { _city = value; }
		}
		private string _city = null;
		#endregion

		#region Property <string> mobile
		[Property("mobile", 15, SqlDbType.VarChar, false, false)]
		public string mobile 
		{
			get { return _mobile; }
			set { _mobile = value; }
		}
		private string _mobile = null;
		#endregion

		#region Property <string> email
		[Property("email", 50, SqlDbType.VarChar, false, false)]
		public string email 
		{
			get { return _email; }
			set { _email = value; }
		}
		private string _email = null;
		#endregion

		#region Property <DateTime> createTime
		[Property("createTime", 16, SqlDbType.DateTime, false, false)]
		public DateTime createTime 
		{
			get { return _createTime; }
			set { _createTime = value; }
		}
		private DateTime _createTime = DateTime.MinValue;
		#endregion
		#endregion


		public bool LoadByIdentity(int personId)
		{
			return DataAccess.SelectByIdentity(this, Convert.ToInt64(personId));
		}


		public bool DeleteByIdentity()
		{
			return DataAccess.DeleteByIdentity(this);
		}
	}
}
